﻿using Framework.Core.Options;
using FreeRedis;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Quartz;
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Volo.Abp.AspNetCore.SignalR;
using Volo.Abp.BackgroundJobs.Quartz;
using Volo.Abp.BackgroundWorkers.Quartz;
using Volo.Abp.Domain;
using Volo.Abp.Modularity;
using Volo.Abp.Quartz;

namespace my.abp.Domain.Shared
{
	/// <summary>
	/// 领域共享层 模块
	/// </summary>
	[DependsOn(
		typeof(AbpDddDomainSharedModule),    // 集成 领域驱动设计（DDD）共享部分 模块
		typeof(AbpBackgroundWorkersQuartzModule),		// 集成 Quartz.NET 任务调度库 模块
		typeof(AbpBackgroundJobsQuartzModule),          // 集成 Quartz 后台作业管理 模块
		typeof(AbpAspNetCoreSignalRModule)				// 集成 SignalR功能 模块
	)]
	public class MyAbpDomainSharedModule : AbpModule
	{
		public override void ConfigureServices(ServiceConfigurationContext context)
		{
			var configuration = context.Services.GetConfiguration();

			Configure<JwtOptions>(configuration.GetSection(nameof(JwtOptions)));                    // jwt配置
			Configure<RefreshJwtOptions>(configuration.GetSection(nameof(RefreshJwtOptions)));		// 刷新jwt配置
		}

		public override void PreConfigureServices(ServiceConfigurationContext context)
		{
			var configuration = context.Services.GetConfiguration();

			//PreConfigure<AbpQuartzOptions>(options =>
			//{
			//	options.Properties = new NameValueCollection
			//	{
			//		{ "quartz.serializer.type","binary" },
			//	};
			//});

			PreConfigure<AbpQuartzOptions>(options =>
			{
				options.Configurator = configure =>
				{
					configure.UseSimpleTypeLoader();
					configure.UseInMemoryStore();
					configure.UseDefaultThreadPool(tp =>
					{
						tp.MaxConcurrency = 10;
					});
				};
			});
		}
	}
}
